package com.coder.algorithm.leetcode

/**
 * [153. 寻找旋转排序数组中的最小值](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/)
 *
 * @author yuhus
 * @date: 2022/3/30
 */
object l_0153 {
    /**
     * 二分查找，排除思想
     *
     *
     */
    fun findMin(nums: IntArray): Int {
        var l = 0
        var r = nums.size - 1
        while (l < r) {
            val mid = (l + r) / 2
            // 排除右侧
            if (nums[r] > nums[mid]) {
                r = mid
            } else {
                // 排除左侧
                l = mid + 1
            }
        }
        return nums[l]
    }
}